<template>
      <el-aside :width="main.isCollapse ? '180px':'64px' ">
    <el-menu :collapse-transition="false" :collapse="!main.isCollapse" active-text-color="rgb(196, 86.4, 86.4)"  background-color="#545454"  text-color="#fff" :default-active="$route.name" class="el-menu-vertical-demo">
          <h3 v-show="main.isCollapse">VUE后台</h3>
          <h3 v-show="!main.isCollapse">VUE</h3>
        <el-menu-item @click="clickMenu(item)" v-for="item in onChildren()" :index="item.name" :key="item.path">
            <el-icon>
                <component class="icons" :is="item.icon"></component>
            </el-icon>
            <span>{{ item.labal }}</span>
        </el-menu-item>

        <el-sub-menu v-for="item in hasChildren()" :index="item.name" :key="item.path">
            <template #title>
                <el-icon>
                    <component class="icons" :is="item.icon"></component>
                </el-icon>
                <span>{{ item.labal }}</span>
            </template>
            <el-menu-item-group>

                <el-menu-item @click="clickMenu(subItem)"  v-for="(subItem, subIndex) in item.children" :index="subItem.name" :key="subIndex">
                    <el-icon>
                        <component class="icons" :is="subItem.icon"></component>
                    </el-icon>
                    <span>{{ subItem.labal }}</span>
                </el-menu-item>

            </el-menu-item-group>
        </el-sub-menu>

    </el-menu>
</el-aside>
</template>

<script setup>
// 引入仓库/创建仓库
import { useAside } from '../store/index.js';
const main = useAside()

// 引入路由router
import { useRouter } from 'vue-router'
const router = useRouter()


const list = [
    {
        path: '/',
        name: 'home',
        labal: '首页',
        icon: 'House'
    },
    {
        path: '/user',
        name: 'user',
        labal: '用户管理',
        icon: 'User'
    },
    {
        labal: '其他',
        icon: 'Location',
        path: '/outher',
        name:'outher',
        children: [
            {

                path: '/page1',
                name: 'page1',
                labal: '页面1',
                icon: 'Suitcase'
            },
            {

                path: '/page2',
                name: 'page2',
                labal: '页面2',
                icon: 'Suitcase'
            }
        ]
    }
]
// 过滤路由
const onChildren = () => {
    return list.filter((item) => !item.children)
}
const hasChildren = () => {
    return list.filter((item) => item.children)
}
// console.log(onChildren());
// console.log(hasChildren());
// 点击侧边栏菜单
const clickMenu = (item) => {
    console.log(item);
    router.push({
        name: item.name
    })
    main.selectMenu(item)
    console.log(main.currentMenu);
    
}


</script>

<style lang="less">
.el-menu{
    border: none;
    h3{
        color: #fff;
        text-align: center;
        line-height: 50px;
        font-weight: 800;
    }
}

</style>